<div class="register-box-body">
  <p class="login-box-msg">注册</p>

  <%= form_for @user, url: {action: 'create'} do |user| %>
      <div class="form-group has-feedback">
        <%= user.text_field :username, class: 'form-control', placeholder: '用户名'%>
      </div>
      <div class="form-group has-feedback">
        <%= user.password_field :password, class: 'form-control', placeholder: '密码'%>
      </div>
      <div class="form-group has-feedback">
        <%= user.password_field :password_confirmation, class: 'form-control', placeholder: '确认密码'%>
      </div>
      <div class="form-group has-feedback">
        <%= user.text_field :product_line, class: 'form-control', placeholder: '产品线(大雅、小雅、收银、智鸿)'%>
      </div>
      <div class="row">
        <div class="col-xs-8"></div>
        <div class="col-xs-4">
          <button type="submit" class="btn btn-primary btn-block btn-flat" id="btn_submit">注册</button>
        </div>
        <!-- /.col -->
      </div>
  <% end %>
</div>

<!--引入错误提示框-->
<%= render partial: 'common/alert', object: @user %>
<script type="text/javascript">
  $(function(){
    $('#btn_submit').click(function(){
      var user_username = $('#user_username').val();
      var user_username_length = user_username.length;
      if (user_username_length == 0 ) {
        alert("用户名不能为空！");
        return false;
      }
      var user_password = $('#user_password').val();
      var user_password_confirmation = $('#user_password_confirmation').val();
      var user_password_length = user_password.length;
      var user_password_confirmation_length = user_password_confirmation.length;
      if (user_password_length == 0 || user_password_confirmation_length == 0) {
        alert("密码不能为空！");
        return false;
      }else {
        if ( user_password != user_password_confirmation ) {
          alert("两次输入密码不一致，请重新输入！");
          return false;
        }else {
          if ( user_password_length < 6  || user_password_confirmation_length< 6 ) {
            alert("密码长度不能少于6位！");
            return false;
          }
        }
      }
      var user_product_line = $('#user_product_line').val();
      var user_product_line_length = user_product_line.length;
      if ( user_product_line != "大雅" && user_product_line != "小雅"  && user_product_line != "收银" && user_product_line != "智鸿" ) {
        alert("产品线只能是大雅、小雅、收银、智鸿");
        return false;
      }else {
        if ( user_product_line_length == 0 ) {
          alert("产品线只能是大雅、小雅、收银、智鸿");
          return false;
        }
      }
      $('form').submit();
    });

  });

</script>
